package com.ityuwen.mengyagushi.album.api;

import com.ityuwen.mengyagushi.album.service.TrackInfoService;
import com.ityuwen.mengyagushi.album.service.VodService;
import com.ityuwen.mengyagushi.common.login.GuiGuLogin;
import com.ityuwen.mengyagushi.common.result.Result;
import com.ityuwen.mengyagushi.model.album.TrackInfo;
import com.ityuwen.mengyagushi.query.album.TrackInfoQuery;
import com.ityuwen.mengyagushi.vo.album.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

	@Autowired
	private TrackInfoService trackInfoService;

	@Autowired
	private VodService vodService;

	@PostMapping("uploadTrack")
	public Result<Object> uploadTrack(MultipartFile file){
		Object obj = this.vodService.uploadTrack(file);
		return Result.ok(obj);
	}

	@GuiGuLogin
	@PostMapping("saveTrackInfo")
	public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo){
		this.trackInfoService.saveTrackInfo(trackInfoVo);
		return Result.ok();
	}

	@GuiGuLogin
	@PostMapping("findUserTrackPage/{page}/{limit}")
	public Result<Page<TrackListVo>> findUserTrackPage(
			@PathVariable("page")Integer page,
			@PathVariable("limit")Integer limit,
			@RequestBody TrackInfoQuery query
			){
		Page<TrackListVo> trackListVoPage = this.trackInfoService.findUserTrackPage(page, limit, query);
		return Result.ok(trackListVoPage);
	}

	@GetMapping("getTrackInfo/{trackId}")
	public Result<TrackInfo> getTrackInfo(@PathVariable("trackId")Long trackId){
		TrackInfo trackInfo = this.trackInfoService.getById(trackId);
		return Result.ok(trackInfo);
	}

	@GuiGuLogin
	@PutMapping("updateTrackInfo/{trackId}")
	public Result updateTrackInfo(@PathVariable("trackId")Long trackId, @RequestBody TrackInfoVo trackInfoVo){
		this.trackInfoService.updateTrackInfo(trackId, trackInfoVo);
		return Result.ok();
	}

	@GuiGuLogin
	@DeleteMapping("removeTrackInfo/{trackId}")
	public Result removeTrackInfo(@PathVariable("trackId")Long trackId){
		this.trackInfoService.removeTrackInfo(trackId);
		return Result.ok();
	}

	@GuiGuLogin(required = false)
	@GetMapping("findAlbumTrackPage/{albumId}/{page}/{limit}")
	public Result<Page<AlbumTrackListVo>> findAlbumTrackPage(
			@PathVariable("albumId")Long albumId,
			@PathVariable("page")Integer page,
			@PathVariable("limit")Integer limit
	){
		Page<AlbumTrackListVo> albumTrackListVoPage = this.trackInfoService.findAlbumTrackPage(albumId, page, limit);
		return Result.ok(albumTrackListVoPage);
	}

	@GetMapping("getTrackStatVo/{trackId}")
	public Result<TrackStatVo> getTrackStatVo(@PathVariable("trackId")Long trackId){
		TrackStatVo statVo = this.trackInfoService.getTrackStatVo(trackId);
		return Result.ok(statVo);
	}

	@GetMapping("findUserTrackPaidList/{trackId}")
	public Result<List<TrackOrderVo>> findUserTrackPaidList(@PathVariable("trackId")Long trackId){
		List<TrackOrderVo> trackOrderVos = this.trackInfoService.findUserTrackPaidList(trackId);
		return Result.ok(trackOrderVos);
	}

	@GetMapping("findBuyTracks/{trackId}/{count}")
	public Result<List<TrackInfo>> findBuyTracks(@PathVariable("trackId")Long trackId, @PathVariable("count")Integer count){
		List<TrackInfo> trackInfos = this.trackInfoService.findBuyTracks(trackId, count);
		return Result.ok(trackInfos);
	}
}

